<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改操作员</title>
<link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<script src="jquery/jquery-1.8.3.min.js"></script>
<style type="text/css">
	body{
		font-family:"微软雅黑","黑体","宋体";
		}
	#kong{
	width: 150px;
	}
	#kong1{
	width: 120px;
	}
	#addoperator{
	margin-left:  150px;
	width: 100px;
	}
	#mainDiv{
		margin-left:300px;
	}
	td{
		height:50px;
	}
</style>
</head>
<body>
	<div id="mainDiv">
		<table>
		<tr>
		<td>
		<label>工号：</label>
		</td>
		<td style="padding-bottom:5px;">
		<span id="userName"></span>
		<label id="kong"></label>
		</td>
		<td>
		<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码：</label>
		</td>
		<td style="padding-bottom:5px;">
		<span id="userPWD"></span>
		</td>
		</tr>
		<tr>
		<td>
		<label>姓名：</label>
		</td>
		<td style="padding-bottom:5px;">
		<span id="operatorName"></span>
		<label id="kong1"></label>
		</td>
		<td>
		<label>电话号码：</label>
		</td>
		<td style="padding-bottom:5px;">
		<span id="operatorTel"></span>
		</td>
		</tr>
		</table>
		<form action="updateOperatorbyUserId.do" class="form-horizontal" method="post" id="updateOperatorFrom" onsubmit="return checkLevel()" enctype="multipart/form-data" >
			<input type="hidden" value="" name="id" id="operatorid"/>
			<label>权限：</label>
			<input name="levels" onchange="checkLevel()" type="checkbox"  value="1">用户管理
			<input name="levels" onchange="checkLevel()" type="checkbox" value="2">车位管理
			<input name="levels" onchange="checkLevel()" type="checkbox" value="3">合同管理
			<input name="levels" onchange="checkLevel()" type="checkbox" value="4">投诉管理
			<label id="operatorLevel" class="help-block">请选择权限</label>
			<br>
			<br>
			<input style="margin-left:200px;" id="updateoperator" type="submit" class="btn btn-warning" value="修改">
		</form>
		
	</div>
	<script type="text/javascript">
		$(function(){
			var id = getParam("id");
			$("#operatorid").val(id);
			$.ajax({
				url:"findOperatorbyUserId.do",
				type:"post",
				async:false,
				data:{"id":id},
				success:function(msg){
					$("#userName").html(msg.user.userName);
					$("#userPWD").html(msg.user.userPWD);
					$("#operatorName").html(msg.operatorName);
					$("#operatorTel").html(msg.operatorTel);
					var checkbox = $("input:checkbox[name='levels']");
					for(var i=0;i<checkbox.length;i++){
						for(var j=0;j<msg.levels.length;j++){
							if(checkbox[i].value==msg.levels[j].levelID){
								checkbox[i].checked=true;
							}
						}
					}
				}			
			})		
		})
		 function getParam(url){
			 var reg
			 = new RegExp("(^|&)"+
			 url +"=([^&]*)(&|$)");
			 var r
			 = window.location.search.substr(1).match(reg);
			if (r!=null) return unescape(r[2]); return null;
		 }
		function checkLevel(){
			var operatorLevel = document.getElementById("operatorLevel");
			var flag = false;
			var checks = document.getElementsByTagName("input");
			for(var i=0; i<checks.length; i++)
			{
			  if (checks[i].name == "levels" && checks[i].checked) {
			  	flag=true;
			  	operatorLevel.innerHTML = "";
			  	break;
			  }
			}
			if(!flag){
				operatorLevel.innerHTML = "请选择权限";
			}
			return flag;
		}
	
	</script>
</body>
</html>